$(document).ready(function(){
    var stepW = 24;
    var description = new Array("It's bad","Not bad","Normal","Good","Excellent");
    var stars = $("#star > li");
    var descriptionTemp;
    $("#showb").css("width",0);
    stars.each(function(i){
        $(stars[i]).click(function(e){
            var starNum = i+1;
            var iri = location.hash.split("iri=")[1];
            var classKey = iri.split('/')[iri.split('/').length-2]+"/"+iri.split('/')[iri.split('/').length-1];
            $.ajax({
                url:'http://www.usources.cn:8080/api/statistics/evaluation',
                type:'GET',
                xhrFields: {
                   withCredentials: true
                },
               crossDomain:true, 
               data:{starNum:starNum,action:1,classKey:classKey},
               success:function(data){
                if(data.code == 200){
                    $("#showb").css({"width":stepW*starNum});
                    descriptionTemp = (i+1)+"星";
                    $(this).find('a').blur();
                    return stopDefault(e);
                }else if(data.code == 1020){
                    layer.msg("您已经评价过!",{icon:2});
                }else{
                    layer.msg("服务异常",{icon:2});
                }
               },error:function(data){
                    console.log(data);
                    layer.msg("服务异常",{icon:2});
               },dataType:'json'});
        });
    });
    stars.each(function(i){
        $(stars[i]).hover(
            function(){
                $(".description").text(description[i]);
            },
            function(){
                if(descriptionTemp != null)
                    $(".description").text("当前评价: "+descriptionTemp);
                else 
                    $(".description").text(" ");
            }
        );
    });
});
function stopDefault(e){
    if(e && e.preventDefault)
           e.preventDefault();
    else
           window.event.returnValue = false;
    return false;
};